#include <stdio.h>
#include <dshow.h>
#pragma comment(lib,"strmiids.lib")
//-lstrmiids -lole32 -loleaut32
void EnumDirveInfo(IEnumMoniker*pEnum);
int main(){
	CoInitialize(NULL);
	ICreateDevEnum*pDevEnum=NULL;
	IEnumMoniker*pAudioEnum=NULL;
	IEnumMoniker*pVideoEnum=NULL;
	HRESULT hr=CoCreateInstance(CLSID_SystemDeviceEnum,NULL,
		CLSCTX_INPROC_SERVER,IID_ICreateDevEnum,(void**)(&pDevEnum));
	if(SUCCEEDED(hr)){
		hr=pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pVideoEnum,0);
		if(hr==NOERROR){
			printf("EnumVideo:\n");
			EnumDirveInfo(pVideoEnum);
		}else{
			printf(TEXT("Sorry, you have no video capture hardware.\r\n\r\n")
			 TEXT("Video capture will not function properly.\n"));
		}
		hr=pDevEnum->CreateClassEnumerator(CLSID_AudioInputDeviceCategory,&pAudioEnum,0);
		if(hr==NOERROR){
			printf("EnumAudio:\n");
			EnumDirveInfo(pAudioEnum);
		}else{
			printf( TEXT("Sorry, you have no audio capture hardware.\r\n\r\n")
			TEXT("Audio capture will not function properly.\n"));
		}
	}else{
		//printf("error\n");
		printf(TEXT("Error Creating Device Enumerator\n"));
	}
	CoUninitialize();
	system("PAUSE");
	return 0;
}

void EnumDirveInfo(IEnumMoniker*pEnum){
	IMoniker *pMoniker=NULL;
	HRESULT hr;
	pEnum->Reset();
//	pEnum->Skip(1);
	while(pEnum->Next(1,&pMoniker,NULL)==S_OK){
		IPropertyBag*pPropBag;
		hr=pMoniker->BindToStorage(0,0,IID_IPropertyBag,(void**)(&pPropBag));
		if (FAILED(hr)){
			pMoniker->Release();
			continue;
		}
		VARIANT varName;
		VariantInit(&varName);
		hr=pPropBag->Read(L"FriendlyName",&varName,0);
		if (SUCCEEDED(hr)){
			CHAR str[10240];
			WideCharToMultiByte(CP_ACP,0,varName.bstrVal,-1,str,10240,NULL,NULL);
			printf("%s\n",str);
		}
		pPropBag->Release();
		pMoniker->Release();
	}
}